<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/head :: htmlhead">
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">打回意见</div>
                <div class="layui-card-body">
                    <form class="layui-form" id="form1" action="" lay-filter="component-form-element">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend th:text="'《'+${title}+'》的打回意见'" style="color: #0C0C0C"></legend>
                            <textarea id="opinion" name="opinion" required lay-verify="required" placeholder="请输入"
                                      class="layui-textarea" style="margin-top: 30px; margin-bottom: 30px"></textarea>
                            <input type="hidden" id="type" th:value="${type}">
                            <button type="button" class="layui-btn" onClick="ok()">确认</button>
                            <button type="button" class="layui-btn layui-btn-primary"
                                    onClick="history.go(-1);">取消
                            </button>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    function ok() {
        var opinion = document.getElementById("opinion").value;
        var datas = {};
        datas["opinion"] = opinion;
        datas["checkid"] = [[${id}]];
        datas["type"] = document.getElementById("type").value;
        if (opinion === "") {
            layer.msg('意见为空！', {icon: 2});
            return false;
        }
        layer.confirm('确定打回？', function (index) {
            layer.close(index);
            console.log("ok");
            $.ajax({
                url: "/confirmSetback",
                async: false,
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(datas),
                success: function (data) {
                    if (data === "success") {
                        layer.open({
                            title: '信息'
                            , content: '打回成功！'
                            , end: function () {
                                history.go(-2);
                            }
                        });
                    } else {
                        layer.open({
                            title: '信息'
                            , content: '打回失败！'
                            , end: function () {
                                location.reload();
                            }
                        });
                    }
                }
            });
        })
    }

    layui.use('form', function () {
        var form = layui.form;
        form.render(null, 'component-form-element');
    });
</script>
</body>
</html>